package com.dimeina.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.dimeina.dao.CategoryDAO;
import com.dimeina.dao.impl.CategoryDAOImpl;
import com.dimeina.dao.impl.ProDAOImpl;
import com.dimeina.service.ProService;
import com.dimeina.util.BaseDAO;
import com.dimeina.vo.Category;
import com.dimeina.vo.PageVo;
import com.dimeina.vo.ProPicPath;
import com.dimeina.vo.ProView;
import com.dimeina.vo.Product;

public class ProServiceImpl implements ProService {
	// 创DAO层对象
	ProDAOImpl proDAOImpl = new ProDAOImpl();
	CategoryDAO categoryDAOImpl = new CategoryDAOImpl();

	// 添加商品详细信息
	// 返回插入记录的“主键”
	public int addPro(Product pro){
		int mainKey = 0;
		try {
			mainKey = proDAOImpl.addPro(pro);
		} catch (Exception e) {
			System.out.println("添加商品详细信息_Service层错误！");
			e.printStackTrace();
		}
		return mainKey;
	}
	
	// 添加商品图片
	public int addProPic(ProPicPath ppp) {
		int result = 0;
		try {
			result = proDAOImpl.addProPic(ppp);
		} catch (Exception e) {
			System.out.println("添加商品图片_Service层错误！");
			e.printStackTrace();
		}
		return result;
	}

	// 删除商品
	public int delProduct(int id) {
		int result = 0;
		try {
			result = proDAOImpl.delPro(id);
		} catch (Exception e) {
			System.out.println("删除商品_Service层错误！");
			e.printStackTrace();
		}
		return result;
	}

	// 修改商品详情
	public int updProduct(Product pro) {
		int result = 0;
		try {
			result = proDAOImpl.updPro(pro);
		} catch (Exception e) {
			System.out.println("修改商品详情_Service层错误！");
			e.printStackTrace();
		}
		return result;
	}
	
	// 修改商品图片
    // 返回int 修改成功的记录条数
	public int updProPic(ProPicPath proPic) {
		int result = 0;
		try {
			result = proDAOImpl.updProPic(proPic);
		} catch (Exception e) {
			System.out.println("修改商品图片_Service层错误！");
			e.printStackTrace();
		}
		return result;
	}

	// 根据id搜索商品详情
	// 返回Product
	public Product findProByID(int id) {
		Product pro = null;
		try {
			pro = proDAOImpl.findProByID(id);
		} catch (Exception e) {
			System.out.println("根据id搜索商品详情_Service层错误！");
			e.printStackTrace();
		}
		return pro;
	}
	
	// 根据id搜索商品详情ProView
	// 返回ProView
	public ProView findProViewByID(int id) {
		ProView proView = null;
		try {
			proView = proDAOImpl.findProViewByID(id);
		} catch (Exception e) {
			System.out.println("根据id搜索商品详情ProView_Service层错误！");
			e.printStackTrace();
		}
		return proView;
	}

	// 根据id搜索商品图片
	// 返回ProPicPath
	public ProPicPath findProPicByID(int id) {
		ProPicPath ppp = null;
		try {
			ppp = proDAOImpl.findProPicByID(id);
		} catch (Exception e) {
			System.out.println("根据id搜索商品图片_Service层错误！");
			e.printStackTrace();
		}
		return ppp;
	}

	// 根据Name搜索商品详情
	public Product findProByName(String name) {
		Product pro = null;
		try {
			pro = proDAOImpl.findProByName(name);
		} catch (Exception e) {
			System.out.println("根据Name搜索商品详情_Service层错误！");
			e.printStackTrace();
		}
		return pro;
	}

	// 根据Name模糊搜索商品详情
	// 返回集合
	public List<Product> findProByDimName(String dimName) {
		List<Product> proList = new ArrayList<Product>();
		try {
			proList = proDAOImpl.findProByDimName(dimName);
		} catch (Exception e) {
			System.out.println("根据Name搜索商品详情_Service层错误！");
			e.printStackTrace();
		}
		return proList;
	}

	// 通过PcategoryID搜索所有同级别的商品
	public List<Product> findProByPCategoryID(int PCategoryID) {
		List<Product> proList = new ArrayList<Product>();
		try {
			proList = proDAOImpl.findProByPCategoryID(PCategoryID);
		} catch (Exception e) {
			System.out.println("通过PcategoryID搜索所有同级别的商品_Service层错误！");
			e.printStackTrace();
		}
		return proList;
	}

	// 搜索所有商品Pro
	public List<Product> findAllPro() {
		List<Product> proList = new ArrayList<Product>();
		try {
			proList = proDAOImpl.findAllPro();
		} catch (Exception e) {
			System.out.println("搜索所有商品_Service层错误！");
			e.printStackTrace();
		}
		return proList;
	}
	
	// 搜索所有商品ProView
	public List<ProView> findAllProView() {
		List<ProView> proViewList = new ArrayList<ProView>();
		try {
			proViewList = proDAOImpl.findAllProView();
		} catch (Exception e) {
			System.out.println("搜索所有商品ProView_Service层错误！");
			e.printStackTrace();
		}
		return proViewList;
	}

	//获得总记录数
	public int getTotalCount() {
		return proDAOImpl.getTotalCount();
	}

	//分页获取商品
	public PageVo<ProView> findProByPaging(int curPageNo, int pageSize) {
		PageVo<ProView> pageVo = null;
		pageVo = proDAOImpl.findProByPaging(curPageNo, pageSize);
		return pageVo;
	}

	

	

	

	


}
